package com.woohua.thread.demo;

/***
 * @title Singleton
 * @description:有序性:单列模式
 *          1、有序性问题原因-指令重排
 *          2、Happens-Before
 *          3、volatile变量规则：全局可见，防止指令重排，Happens-Before于后续对这个volatile变量的读操作
 * @author woo hua
 * @version 1.0.0
 * @create 2023/3/9 11:21
 **/
public class Singleton {

    private static Singleton singleton;

    private Singleton() {

    }

    public static Singleton getSingleton() {
        if(null == singleton) {
            synchronized (Singleton.class) {
                if(null == singleton) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}
